package com.baturu.vin.hyundai.dealV2Mapping;

import com.baturu.vin.hyundai.dal.dao.DealPartsDAO;
import com.baturu.vin.test.AbstractBaseCase;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @Author: chenjiahao
 * @Time: 2019/8/24
 */
public class CreatePartsCarType extends AbstractBaseCase {

    @Autowired
    DealPartsDAO dealPartsDAO;

    @Test
    public void insert() {
        int hyundaiPartsMaxId = dealPartsDAO.findHyundaiPartsMaxId();
//        int hyundaiPartsMaxId = dealPartsDAO.findHyundaiDcPartsMaxId();
        int start = 1;
        int stamp = 20000;
        int end = 0;
        String sql ="insert into hyundaiKia_parts_cartype (parts_code,epc_carType_code,car_system_id,brand,MJ)\n" +
                "\n" +
                "SELECT DISTINCT finalpartscode,t.bpno,t1.carSystemId,t1.brand,t2.mj FROM `hyundai_parts` t\n" +
                "INNER JOIN hyundai_carsystem_mapping t1 on t1.bpno = t.bpno and t1.carSystemId !=0\n" +
                "INNER JOIN hyundai_bpno_mj t2 on t2.bpno = t1.bpno  and left(t.starttime,4) <=t2.mj and left(t.endtime,4) >=t2.mj \n" +
                "where t.finalPartsCode !='' ";
        while (start<hyundaiPartsMaxId){
            end = start+stamp;
            String sql1 = sql+"AND t.id >= "+start+" AND t.id<"+end;
            dealPartsDAO.insertParts(sql1);
//            dealPartsDAO.updateDcParts(start, end);
            System.out.println("已更新到"+end);
            start+=stamp;
        }
        if(end<hyundaiPartsMaxId){
//            dealPartsDAO.updateDcParts(end, hyundaiPartsMaxId);
            String sql1 = sql+"AND t.id >= "+end+" AND t.id<"+hyundaiPartsMaxId;
            dealPartsDAO.insertParts(sql1);
        }
    }

}
